package com.gopay.common.cps.dao.cbrmb.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.cbrmb.CbRmbWaybillDAO;
import com.gopay.common.domain.cbrmb.CbRmbWaybill;

/**
 * @ClassName CbRmbWaybillDAOImpl
 * @Description CbRmbWaybill实体类查询DAO
 * @author b.zou
 * @date 2016年12月8日 下午3:01:45
 * @Copyright ©www.gopay.com.cn Inc.All rights reserved.
 */
@Repository(value = "cbRmbWaybillDAO")
public class CbRmbWaybillDAOImpl extends BaseDAOImpl<CbRmbWaybill, Integer> implements CbRmbWaybillDAO {

    @Override
    public CbRmbWaybill findByCombineParams(String merOrderId,String wayBill,String carrierCode) {
        Map<String, Object> param = new HashMap<>();
        param.put("merOrderId", merOrderId);
        param.put("wayBill", wayBill);
        param.put("carrierCode", Integer.parseInt(carrierCode));
        param.put("isDel", "0");
        String hql = "from CbRmbWaybill where merOrderId=:merOrderId and carrierCode=:carrierCode and waybill=:wayBill and isDeleted=:isDel";
        List<CbRmbWaybill> ss = findByHql(hql, param);
        return (null == ss || 0 == ss.size()) ? null : ss.get(0);
    }

    @Override
    public CbRmbWaybill findBySq(String sqNo) {
        Map<String, Object> param = new HashMap<>();
        param.put("sqNo", Integer.parseInt(sqNo));
        param.put("isDel", "0");
        String hql = "from CbRmbWaybill m where m.sq=:sqNo and isDeleted=:isDel";
        List<CbRmbWaybill> ss = findByHql(hql, param);
        return (null == ss || 0 == ss.size()) ? null : ss.get(0);
    }
    
	@Override
	public CbRmbWaybill findByGopayOrderId(String gopayOrderId) {
		Map<String,Object> param = new HashMap<>();
		param.put("gopayOrderId", gopayOrderId);
		param.put("isDel", "0");
		String hql = "from CbRmbWaybill m where m.gopayOrderId=:gopayOrderId and isDeleted=:isDel";
		List<CbRmbWaybill> ss = findByHql(hql, param);
		return (null == ss || 0 == ss.size()) ? null : ss.get(0);
	}

    @Override
    public List<CbRmbWaybill> findEffectiveByMerOrderId(String merOrderId, String custId) {
        String hql = "from CbRmbWaybill where custId=:custId and merOrderId=:merOrderId and isDeleted=:isDel";
        Map<String, Object> param = new HashMap<>();
        param.put("custId", custId);
        param.put("merOrderId", merOrderId);
        param.put("isDel", "0");
        return super.findByHql(hql, param);
    }

    @Override
    public List<CbRmbWaybill> findByUniqueConditions(String custId, String merOrderId, Integer carrierCode,
            String freightNumber) {
        String hql = "from CbRmbWaybill where custId=:cust_id and merOrderId=:merOrder_id and carrierCode=:carrier_code and waybill=:freight_number and isDeleted=:isDel";
        Map<String, Object> param = new HashMap<>();
        param.put("cust_id", custId);
        param.put("merOrder_id", merOrderId);
        param.put("carrier_code", carrierCode);
        param.put("freight_number", freightNumber);
        param.put("isDel", "0");
        return super.findByHql(hql, param);
    }

}
